//
//  BLBiometric.h
//  CALayer
//
//  Created by Benz.L on 24/08/2018.
//  Copyright © 2018 BenzL. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <LocalAuthentication/LocalAuthentication.h>

///
/// @discussion 生物学检测类封装，包括指纹或面容ID.
/// @note       请在info.plist中增加NSFaceIDUsageDescription权限申请说明，否则无法使用FaceID
///
__API_AVAILABLE(ios(8.0))
@interface BLBiometric : NSObject

/**
 @brief 检测设备生物验证权限
 @param error 错误回调,error==nil表示有效，否则失败 @see LAError.h或底部说明
 @return YES表示生物检测有效，否则为NO
 */
+ (BOOL)canBiometry:(LAPolicy)policy error:(NSError **)error;

+ (LABiometryType)biometryTypeWithPolicy:(LAPolicy)policy error:(NSError **)error API_AVAILABLE(ios(11.0));

/**
 @brief 请求指纹检测
 @param reason 文字描述
 @param fallbackTitle 首次检测失败后出现的可选选项
 @param complete 检测结果回调,error==nil表示成功，否则失败 @see LAError.h
 @note Available in iOS8.0+
 */
+ (void)biometryPolicy:(LAPolicy)policy reason:(nonnull NSString *)reason fallbackTitle:(NSString *)fallbackTitle complete:(void(^)(NSError *error))complete;

/**
 @brief 请求指纹检测
 @param reason 文字描述
 @param fallbackTitle 首次检测失败后出现的可选选项
 @param cancelTitle 取消按钮title, @note Available in iOS10.0+
 @param complete 检测结果回调,error==nil表示成功，否则失败 @see LAPublicDefines.h
 */
+ (void)biometryPolicy:(LAPolicy)policy reason:(nonnull NSString *)reason fallbackTitle:(NSString *)fallbackTitle cancelTitle:(NSString *)cancelTitle complete:(void(^)(NSError *error))complete;

@end

/*
 LAErrorBiometryNotEnrolled : 没有设置指纹或面容ID
 LAErrorBiometryNotAvailable: TouchID/FaceId无效
 LAErrorTouchIDLockout      : 多次输入错误
 LAErrorPasscodeNotSet      : 没有设置密码解锁
 LAErrorUserFallback        : 用户选择手动输入密码解锁
 LAErrorUserCancel          : 用户取消操作
 LAErrorAuthenticationFailed: 验证失败
 LAErrorSystemCancel        : 被系统取消，如来电、锁屏、home键等
 LAErrorAppCancel           : 被App取消了授权 (如进入后台等)
 LAErrorInvalidContext      : LAContext对象无效
 */

